package com.asia5b.a5mall.middleware.logic.viewmodel.member

import androidx.lifecycle.MutableLiveData
import com.asia5b.a5mall.middleware.base.SimpleNetParams
import com.asia5b.a5mall.middleware.base.SimpleViewModel
import com.asia5b.a5mall.middleware.model.base.ResultModel
import com.asia5b.a5mall.middleware.model.member.MessageModel
import io.reactivex.functions.Consumer

class MessageActivityVM:SimpleViewModel() {
  private var page = 1
  private var sumPage = 1000

    /**
     * 未读
     * http://47.88.223.5:4001/members/member-nocice-logs?page_no=1&page_size=5&read=0
     * 所有
     * http://47.88.223.5:4001/members/member-nocice-logs?page_no=1&page_size=5&type=all
     */
    fun getDatas(refresh: Int) {
        if (refresh <= 1) {
            page = 1
            sumPage = 1000
        }
        if (page > sumPage) {
//            loadMvpView.dismissLoadingBar()
            loadingLiveData.value=1
            return
        }
        val observable = memberApi.getMessageList("all",page)
        baseSubscribe(observable, SimpleNetParams(isShowLoading = refresh==0),Consumer { resultModel ->
            sumPage = resultModel.sumPage
            page = resultModel.page+1
//            providerView().getDatasResult(resultModel.data!!)
            getDatasResultLiveData.value=resultModel
        })
    }
    val getDatasResultLiveData=MutableLiveData<ResultModel<ArrayList<MessageModel>>>()
}